/**
 * 七牛云上传
 */

const qiniu = require('qiniu')

const config = {
  AK: 'UvhgdYiKhbsbcGTqfEmb3PADZ744_CQt1dGgE8Md',
  SK: 'pji2x1haAnqhDpqRmJgXCB47Ao_j0-rR5e7BygVg',
  Bucket: 'wdtkm'
}

/**
 * 获取七牛云token
 * @returns {object}
 */
export function GetQiniuToken() {
  const mac = new qiniu.auth.digest.Mac(config.AK, config.SK)
  let code = '1'
  const msg = ''
  const data = {}
  const options = {
    scope: config.Bucket,
    expires: 3600 * 24
  }
  const putPolicy = new qiniu.rs.PutPolicy(options)
  const uploadToken = putPolicy.uploadToken(mac)
  if (uploadToken) {
    code = '0'
    data.uploadToken = uploadToken
    return data
  }
}
